package com.jdls.day16.work;

import java.util.concurrent.ArrayBlockingQueue;

/**
 * @author 嘉德罗斯
 * @date 2021/8/7
 */
public class Test4 {
    public static void main(String[] args) {
        //4. 使用阻塞队列改进上面的案例
        ArrayBlockingQueue arr = new ArrayBlockingQueue<>(1);
        new Thread(()->{
            while (true){
                //synchronized (Test4.class) {
                    try {
                        arr.put("汉堡");
                        System.out.println("做汉堡");
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                //}
            }
        }).start();
        new Thread(()->{
            while (true) {
                //synchronized (Test4.class) {
                    try {
                        System.out.println("吃" + arr.take());
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
           // }
        }).start();
    }
}
